<?
/*--|	DB
  Software: Socially
   Version: 1.0
   Contact: http://socially.googlecode.com
      Info: http://socially.googlecode.com
   Support: http://socially.googlecode.com
-------------------------------------------------------------------------- 
    Author: goker.cebeci | http://gokercebeci.com
-------------------------------------------------------------------------- 
   License: Distributed under the GNU General Public License (GPL)
            http://www.gnu.org/licenses/gpl.html
 This program is distributed in the hope that it will be useful - WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 FITNESS FOR A PARTICULAR PURPOSE.
-------------------------------------------------------------------------*/
$db_connection;
class db {
    protected static $dbCharSet = 'utf8';
    public static function connect(){
        global $db_connection;
        if(SETUP || ACCESS >= DEBUG){
            if(!DBHOST || !DBNAME || !DBUSER || !DBPASS){ echo _('Please, check mysql connection data in _conf.php'); exit; }
                $db_connection = @mysqli_connect(DBHOST,DBUSER,DBPASS,DBNAME);
            /* check connection */
            if (mysqli_connect_errno()) {
                echo sprintf(_('Connect failed: %s'), mysqli_connect_error());
                exit;
            }
        } else {
            $db_connection = @mysqli_connect(DBHOST,DBUSER,DBPASS,DBNAME);
        }
        mysqli_set_charset($db_connection,self::$dbCharSet);
    }
    public static function query($query, $return = false, $list = false, $fetch = 'mysqli_fetch_object'){
        global $db_connection,$debug;
        $result = mysqli_query($db_connection, $query);
        $caller = debug_backtrace();
        $error = mysqli_error($db_connection);
        if(ACCESS >= DEBUG) $debug[] = array('query' => 'self::'.$query, 'file' => $caller[0]['file'],'line' => $caller[0]['line'],'error'=>$error);
        if($return){
            while($i = @$fetch($result)) $r[] = $i;
            @mysqli_free_result($result);
            return (count($r)>1 || $list)?$r:$r[0];
        } return $error;
    }
    public static function insertid(){
        global $db_connection;
        return mysqli_insert_id($db_connection);
    }
    public static function disconnect(){
        global $db_connection;
        mysqli_close($db_connection);
    }
}
?>
